<?php
/**
 * Tickets Controller
 *
 * PHP versions 4 and 5
 *
 * Infectamic: Free online role playing game, easily playable by browser. (http://infectamic.goldzoneweb.info)
 * Copyright 2011, Loic Chardonnet
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2011, Loic Chardonnet
 * @link          http://infectamic.goldzoneweb.info Infectamic
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
class TicketsController extends AppController {

    var $name = 'Tickets';

    /**
     * Auto generated admin functions.
     */

    function vogon_index() {
        $this->Ticket->recursive = 0;
        $this->set('tickets', $this->paginate());
    }

    function vogon_view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid ticket', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('ticket', $this->Ticket->read(null, $id));
    }

    function vogon_add() {
        if (!empty($this->data)) {
            $this->Ticket->create();
            if ($this->Ticket->save($this->data)) {
                $this->Session->setFlash(__('The ticket has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The ticket could not be saved. Please, try again.', true));
            }
        }
        $authors = $this->Ticket->Author->find('list');
        $tags = $this->Ticket->Tag->find('list');
        $this->set(compact('authors', 'tags'));
    }

    function vogon_edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid ticket', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Ticket->save($this->data)) {
                $this->Session->setFlash(__('The ticket has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The ticket could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Ticket->read(null, $id);
        }
        $authors = $this->Ticket->Author->find('list');
        $tags = $this->Ticket->Tag->find('list');
        $this->set(compact('authors', 'tags'));
    }

    function vogon_delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for ticket', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->Ticket->delete($id)) {
            $this->Session->setFlash(__('Ticket deleted', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->Session->setFlash(__('Ticket was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }
}
?>